<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./lib/axios.js"></script>
</head>

<body>
  <button id="get">发起get请求</button>
  <button id="post">发起post请求</button>
  <button id="axios_get">发起axios_get请求</button>
  <button id="axios_post">发起axios_post请求</button>
  <script>
    document.querySelector('#get').addEventListener('click', function () {
      const url = 'http://www.liulongbin.top:3006/api/get'
      const obj = { name: 'zs', age: 20 }
      // axios.get(url地址, { params:写要传的数据，如果无，可不写}).then(写回调函数)
      axios.get(url, { params: obj }).then(res => {
        console.log(res)
        //res.data才是服务器返回的数据
        console.log(res.data)
      })
    })

    document.querySelector('#post').addEventListener('click', function () {
      const url = 'http://www.liulongbin.top:3006/api/post'
      // axios.post(url地址, { data:写要传的数据，如果无，可不写}).then(写回调函数)
      const obj = { name: 'zs', age: 20 }
      axios.post(url, { data: obj }).then(res => {
        console.log(res)
        //res.data才是服务器返回的数据
        console.log(res.data)
      })
    })

    document.querySelector('#axios_get').addEventListener('click', () => {
      axios({
        method: 'GET',//请求类型
        url: 'http://www.liulongbin.top:3006/api/get',//url地址
        params: { name: 'zs', age: 20 },//传入的数据，get写params
      }).then(res => {//回调函数
        console.log(res)
      })
    })
    document.querySelector('#axios_post').addEventListener('click', () => {
      axios({
        method: 'POST',//请求类型
        url: 'http://www.liulongbin.top:3006/api/post',//url地址
        data: { name: 'zs', age: 20 },//传入的数据，post写data
      }).then(res => {//回调函数
        console.log(res)
      })
    })

  </script>
</body>

</html>